*****************************
*Analysis
*****************************

//Call household data, merge with election relevant data (RRSVTribal), clean  	
	*Households in Schedule 29.1: Living Conditions of Tribals 	
	use NSS44_29_1_Household, clear 
	merge m:1 pc91_state_region using RRSVTribal
	g HHSize = B5_q1
	g HHHeadMale = B5_q10 == "1"
	rename B5_q11 LandPos
	g LnLandPos = ln(LandPos + 1) //too many huge outliers. Add 1 because lots of 0s. 
	g ResideYrs = B5_q12 == "4"
	g OwnDwellLand = B14_q2 == "1"
	g HouseArea = B14_q3 
	g AnimalShared = B14_q8  == "1"
	g TV = (B5_q21 == "1")
	g Radio = (B5_q22 == "1")
	g Cinema = (B5_q23 == "1")
	g Stage = (B5_q24 == "1")
	g Newspaper = (B5_q25 == "1")
	rename B5_q9 StateTribeNo
	egen Tribe = group(State StateTribeNo)

//Household summary stats (Table 3)
	estpost summ HHSize HHHeadMale LandPos ResideYrs OwnDwellLand HouseArea AnimalShared TV Radio Cinema Stage Newspaper if Stratum_Type=="1"
	estpost summ HHSize HHHeadMale LandPos ResideYrs OwnDwellLand HouseArea AnimalShared TV Radio Cinema Stage Newspaper if Stratum_Type=="2"


//Columns 1-5 of Table 7 in the paper (titled "Tribal Isolation"). Column 6 is based on individual data. Columns 1-5 are based on household data. 
	//Stratum Type I 
	estimates drop _all 
	//controls: sector is urban/rural, stratum can be whole districts or subdistricts, sample is general/special, area is type 1 or type 2, village type is more than 50 percent? Nothing changes if we add more controls (sector or whether the head answers questions) 
	eststo: ivreghdfe TV CF (RF = RCF) if Stratum_Type=="1", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) first // really robust 
	eststo: ivreghdfe Radio CF (RF = RCF) if Stratum_Type=="1", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) // really robust to controls 
	eststo: ivreghdfe Cinema CF (RF = RCF) if Stratum_Type=="1", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) 
	eststo: ivreghdfe Stage CF (RF = RCF) if Stratum_Type=="1", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) 
	eststo: ivreghdfe Newspaper CF (RF = RCF) if Stratum_Type=="1", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) 
	//Stratum Type II 
	estimates drop _all 
	eststo: ivreghdfe TV CF (RF = RCF) if Stratum_Type=="2", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) first // really robust to controls 
	eststo: ivreghdfe Radio CF (RF = RCF) if Stratum_Type=="2", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) // really robust to controls 
	eststo: ivreghdfe Cinema CF (RF = RCF) if Stratum_Type=="2", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) 
	eststo: ivreghdfe Stage CF (RF = RCF) if Stratum_Type=="2", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) 
	eststo: ivreghdfe Newspaper CF (RF = RCF) if Stratum_Type=="2", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) 



//Call individual data, merge with election relevant data (RRSVTribal), clean  	
	use NSS44_29_1_Person, clear 
	merge m:1 pc91_state_region using RRSVTribal
	drop _merge
	preserve 
	use NSS44_29_1_Household, clear 
	keep Key_hhno VillType B5_q9 
	save HHTribe, replace 
	restore 
	merge m:m Key_hhno using HHTribe
	g Working = B8_c6 == "1" 
	tab B8_c11
	destring B8_c11, gen(Activity)
	keep if Activity<91 /*gets rid of students. need them for the mother tongue variable that tells us whether people are educated in their mother tongue*/
	tab B8_c7
	g CasualWageLabour = (B8_c7=="41")|(B8_c7=="51")
	g TotalEarnLstWk = B8_c17 //in kind plus cash 
	g ReportsEarnings = B8_c17 != . 
	g LnTotal = ln(TotalEarnLstWk)
	rename B5_q9 StateTribeNo
	egen Tribe = group(state StateTribeNo)
	encode state_region, gen(StateRegion)
	

//Individual summary stats (Table 3)	
	estpost summ Working CasualWageLabour ReportsEarnings TotalEarnLstWk if Stratum_Type=="1"
	summ TotalEarnLstWk if Stratum_Type=="1", d //for median earnings 
	estpost summ Working CasualWageLabour ReportsEarnings TotalEarnLstWk  if Stratum_Type=="2"
	summ TotalEarnLstWk if Stratum_Type=="2", d //for median earnings 
	


//Columns 6 of Table 7 in the paper (titled "Tribal Isolation"). Column 6 is based on individual data. Columns 1-5 are based on household data. 	
	//Stratum Type I 
	estimates drop _all 
	eststo: ivreghdfe LnTotal CF (RF = RCF) if Stratum_Type=="1", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) first 
	//Stratum Type II 
	estimates drop _all 
	eststo: ivreghdfe LnTotal CF (RF = RCF) if Stratum_Type=="2", absorb(state stratum sample Sub_round B1_q2_Area Tribe VillType) cluster(state_region) first 


